#pragma once
#include "noncopyable.h"
#include "eventloop.h"
#include "thread.h"

#include <functional>
#include <mutex>
#include <condition_variable>
class EventLoopThread : noncopyable{
public:
    using ThreadInitCallBack = std::function<void(EventLoop*)>;

    EventLoopThread(const ThreadInitCallBack& cb, const std::string& name = std::string());
    ~EventLoopThread();

    EventLoop* startLoop();
private:
    EventLoop* loop_;
    bool exiting_;
    Thread thread_;

    std::mutex mutex_;
    std::condition_variable cond_;
    // 线程初始化用户回调
    ThreadInitCallBack callback_;
    
    // thread 的执行逻辑
    void threadFunc();

};

